$(document).ready(function () {
    reloadAppList();
    loadTaskProcess();
    let clipboard = new ClipboardJS($('.js-clibtext')[0]);
    clipboard.on('success', function (e) {
        layer.alert('复制成功', {offset: '15px', time: 1000, icon: 1});
    });
    clipboard.on('error', function (e) {
        layer.alert('复制失败', {offset: '15px', time: 1000, icon: 1});
    });
});

function reloadAppList() {
    $('#appList').load('/app/versionApp/index', {'version_id': $('#versionId').val()});
}

function loadTaskProcess() {
    layui.use(['layer'], function () {
        var $ = layui.jquery;
        var layer = layui.layer; //加载layer模块
        $.post('/app/versionApp/task/status', {'versionId': $('#versionId').val()}, function (msg) {
            if (msg && msg.data) {
                layer.msg(msg.data, {offset: '15px', time: 3000, icon: 1}, function () {
                    console.log("reload...")
                    window.location.reload();
                });
            } else {
                //如果没有正在处理的任务，再看看上一次的代码规范检查结果
                $.post('/app/versionApp/task/pmdres', {'versionId': $('#versionId').val()}, function (res) {
                    if (res && res.data) {
                        let message = res.data.replace(new RegExp('\n','ig'),'<br>');
                        message = message.replace(new RegExp(' ','ig'),'&nbsp;');
                        layer.alert(message, {area: ['600px', '400px'],offset: '15px', icon: 1,btn:['知道了']},function (index) {
                            // $.post('/app/versionApp/task/pmdresclear', {'versionId': $('#versionId').val()}, function (data) {
                                layer.close(index);
                            // });
                        });
                    }
                })
            }
        })
    });
}